// SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd.
// SPDX-License-Identifier: MIT
package metrics

import (
        "github.com/stretchr/testify/assert"
        "testing"
)

func TestParseFloat(t *testing.T) {
        tests := []struct {
                name    string
                input   string
                want    float64
                wantErr bool
        }{
                {"valid float", "123.45", 123.45, false},
                {"with spaces", "  123.45  ", 123.45, false},
                {"invalid", "abc", 0, true},
        }

        for _, tt := range tests {
                t.Run(tt.name, func(t *testing.T) {
                        got, err := ParseFloat(tt.input)
                        if tt.wantErr {
                                assert.Error(t, err)
                        } else {
                                assert.NoError(t, err)
                                assert.Equal(t, tt.want, got)
                        }
                })
        }
}

func TestSplitAndTrim(t *testing.T) {
        tests := []struct {
                name  string
                input string
                sep   string
                want  []string
        }{
                {"simple", "a,b,c", ",", []string{"a", "b", "c"}},
                {"with spaces", " a , b , c ", ",", []string{"a", "b", "c"}},
                {"empty", "", ",", []string{}},
        }

        for _, tt := range tests {
                t.Run(tt.name, func(t *testing.T) {
                        got := SplitAndTrim(tt.input, tt.sep)
                        assert.Equal(t, tt.want, got)
                })
        }
}

